#include<iostream>
using namespace std;

struct TreeNode {
     int val;
     TreeNode *left;
     TreeNode *right;
     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 };

class Solution {
public:
    int cnt = 0;
    int ans = 0;
    int kthLargest(TreeNode* root, int k) {
        dfs(root, k);
        return ans;

    }

    void dfs(TreeNode*root, int k){
        if(root == NULL)return;
        dfs(root->right, k);
        if(++cnt==k){
            ans = root->val;
        }
        dfs(root->left, k);
    }
};